package thread;

/**
 * 获取运行当前代码片段的线程
 *
 */
public class ThreadInfoDemo {
    public static void main(String[] args) {
        //主线程进入mian方法后,执行下面操作会将自身返回
        Thread main = Thread.currentThread();
        System.out.println("主线程:"+main);
        showInfo();
    }

    public static void showInfo(){
        Thread t = Thread.currentThread();
        System.out.println("运行showInfo的线程是:"+t);

        String name = t.getName();
        System.out.println("名字:"+name);//获取线程的名字

        long id = t.getId();
        System.out.println("唯一标识:"+id);//获取该线程的唯一标识

        int priority = t.getPriority();
        System.out.println("优先级:"+priority);//线程的优先级

        Boolean isAlive = t.isAlive();//当前线程是否还活着
        Boolean isDaemon = t.isDaemon();//当前线程是否为守护线程
        Boolean  isInterrupted = t.isInterrupted();//当前线程是否被中断
        System.out.println("是否活着"+isAlive);
        System.out.println("是否为守护线程"+isDaemon);
        System.out.println("是否被中断"+isInterrupted);


    }


}
